package com.greateamd.timetableasy.client.widgets.university;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.greateamd.timetableasy.client.domain.EventType;
import com.greateamd.timetableasy.domain.University;

public class UniversityPanel extends Composite {
	
	@UiTemplate("UniversityPanel.ui.xml")
	interface UniversityPanelUIBinder extends UiBinder<Widget, UniversityPanel> {}
	private static UniversityPanelUIBinder uiBinder = GWT.create(UniversityPanelUIBinder.class);
	
	@UiField TextBox nameTb;
	@UiField TextBox addressTb;
	@UiField Button applyBt;
	
	private University university = new University();
	
	public UniversityPanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	public UniversityPanel(final EventType typeRestriction) {
		this();
	}

	//---------------------------------------------------------------------
	//-------------------------- UI Action	
	private void setPanel(){
		nameTb.setValue(university.getName());
		addressTb.setValue(university.getAddress());
	}
	

	//---------------------------------------------------------------------
	//-------------------------- Handler
	@UiHandler("applyBt")
	void onSubmitBtClick(ClickEvent e){
		university.setName(nameTb.getValue());
		university.setAddress(addressTb.getValue());
	}
	
	public void setUniversity(University u){
		university = u;
		setPanel();
	}

	public University getUniversity() {
		return university;
	}
}
